package net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TcpClientDemo02 {
    public static void main(String[] args) {

        try {

            Socket socket = new Socket("127.0.0.1", 8888);

            OutputStream out = socket.getOutputStream();
            InputStream in = socket.getInputStream();

            String content = "再给我两分钟，让我把记忆结成冰";
            out.write(content.getBytes());

            byte[] bytes = new byte[1024];
            int length = in.read(bytes);
            System.out.println(new String(bytes, 0, length));

            in.close();
            out.close();
            socket.close();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
